package toy.keli.edic.domain.model

import toy.keli.edic.data.Db
import toy.keli.edic.data.config.PathConf
import toy.keli.edic.data.local.entity.Meaning
import toy.keli.edic.data.local.entity.BookmarkEntity
import toy.keli.edic.data.local.entity.DictionaryEntity
import toy.keli.edic.data.local.entity.HistoryEntity
import toy.keli.edic.data.model.Query
import toy.keli.edic.ui.history.HistoryViewModel
import toy.keli.edic.util.FileUtil

data class WordModel(
    val meanings: List<Meaning>?,
    val word: String,
    val wordsetId: String,
    val level: Int,
    var status: Int = 0,  // 初始、认识、模糊、忘记
    var ch: String?="",
    val date:String ="" //时间如果需要 格式为yyyy-MM-dd HH:mm:ss
) {
    var pic=""
    var isStudyed:Boolean = false
    fun toBookmarkEntity(): BookmarkEntity {
        return BookmarkEntity(meanings, word, wordsetId,
            ch=ch?:"", intime = System.currentTimeMillis()
        )
    }

    fun toHistoryEntity(): HistoryEntity {
        return HistoryEntity(meanings, word, wordsetId, level, status,
            System.currentTimeMillis(), ch)
    }

    fun toDictionaryEntity(): DictionaryEntity {
        return DictionaryEntity("", word, wordsetId, ch,level)
    }

    fun hasPic(): Boolean {
        var imgFile = PathConf.imgs+word+".jpg"
        pic = imgFile
        return FileUtil.exists(imgFile)
    }

    fun getYinBiao(): Map<String, String> {
        var yb = meanings?.first()?.symbol
        if(yb==null) {
            return mapOf<String,String>()
//            yb = listOf("","")
        }
        if(yb.size==1) yb = listOf(yb[0],"")

        return mapOf("美" to yb[0],"英" to yb[1])
    }

    companion object {
        const val STATUS_KNOW = 1
        const val STATUS_VAGUE = 2
        const val STATUS_FORGET = 3
        const val STATUS_NEW = 0
        val demoModel:WordModel = WordModel(
            Meaning.decode("[{\"def\": \"an expression of greeting\", \"example\": \"Every morning they exchanged polite hellos.\", \"speech_part\": \"noun\", \"synonyms\": [\"hullo\", \"hi\", \"howdy\", \"how-do-you-do\"], \"symbol\": [\"[həˈləʊ]\", \"[heˈləʊ]\"], \"phrase\": [\"say Hello\"], \"antonym\": [\"int.goodbye\"], \"def_ch\": \"问候的表情\", \"example_ch\": \"每天早上他们都礼貌地打招呼。\"}]"),
           "hello","0",0,0,"喂(打招呼)","2000-01-01 00:00:00")
    }
}